<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>删除垃圾投放记录</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
            color: #333;
        }
        .container {
            max-width: 1200px;
            margin: 20px auto;
            padding: 20px;
            background-color: #fff;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            border-radius: 8px;
        }
        h1 {
            text-align: center;
            color: #007BFF;
            margin-bottom: 20px;
        }
        .delete-container {
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        label {
            margin-bottom: 5px;
            font-weight: bold;
        }
        input {
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            margin-bottom: 15px;
            width: 200px;
        }
        button {
            padding: 10px 20px;
            background-color: #007BFF;
            color: #fff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        button:hover {
            background-color: #0056b3;
        }
        .error, .success {
            color: red;
            text-align: center;
            margin-top: 10px;
        }
        .success {
            color: green;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="header">
        <h1>删除垃圾投放记录</h1>
    </div>
    <div class="delete-container">
        <label for="residentId">请输入居民编号：</label>
        <input type="text" id="residentId" name="residentId" required>
        <button onclick="deleteWasteRecordByResidentId()">删除</button>
        <div class="error" id="error-message"></div>
        <div class="success" id="success-message"></div>
    </div>
</div>

<script>
    function deleteWasteRecordByResidentId() {
        const residentId = document.getElementById('residentId').value;
        if (!residentId) {
            document.getElementById('error-message').innerText = '请输入居民编号！';
            document.getElementById('success-message').innerText = '';
            return;
        }

        fetch(`http://localhost:8081/waste/deleteWasteRecordByResidentId?residentId=${residentId}`)
            .then(response => {
                if (response.status === 200) { // 假设后端在成功时返回 HTTP 状态码 200
                    document.getElementById('error-message').innerText = '';
                    document.getElementById('success-message').innerText = '删除成功！';
                    document.getElementById('residentId').value = '';
                } else {
                    throw new Error('删除失败');
                }
            })
            .catch(error => {
                console.error('错误:', error);
                document.getElementById('error-message').innerText = '删除失败，请稍后再试！';
                document.getElementById('success-message').innerText = '';
            });
    }
</script>
</body>
</html>